package com.hsgene.user.dto.address;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.hsgene.common.util.basic.SimpleRegexUtils;
import com.hsgene.common.util.date.TimeJsonDeserializer;
import com.hsgene.common.util.exception.IllegalParamException;
import com.hsgene.common.util.validation.FieldChecker;

import java.io.Serializable;
import java.util.Date;

/**
 * 用户收货地址
 *
 * @author wangbing
 * @version 1.0, 2018/8/6
 */
public class ConsignAddressDto implements Serializable {

    private static final long serialVersionUID = 6925895721765039172L;
    /**
     * 主键id
     */
    private Long id;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 用户类型
     */
    private String userType;

    /**
     * 省级id
     */
    private Long province;

    /**
     * 省名
     */
    private String provinceName;

    /**
     * 市级id
     */
    private Long city;

    /**
     * 市名
     */
    private String cityName;

    /**
     * 区县级id
     */
    private Long county;

    /**
     * 区县名
     */
    private String countyName;

    /**
     * 详细地址
     */
    private String address;

    /**
     * 收货人姓名
     */
    private String consigneeName;

    /**
     * 收货人电话
     */
    private String consigneePhone;

    /**
     * 地址是否有效
     */
    private Boolean available;

    /**
     * 是否是默认收货地址
     */
    private Boolean defaultAddress;

    /**
     * 创建时间
     */
    @JsonDeserialize(using = TimeJsonDeserializer.class)
    private Date createTime;

    /**
     * 更细时间
     */
    @JsonDeserialize(using = TimeJsonDeserializer.class)
    private Date updateTime;

    public void check() {
        FieldChecker.checkEmpty(userId, "userId");
        FieldChecker.checkEmpty(userType, "userType");
        defaultAddress = defaultAddress == null ? Boolean.FALSE : defaultAddress;
        simpleCheck();
    }

    public void simpleCheck() {
        FieldChecker.checkEmpty(province, "province");
        FieldChecker.checkEmpty(city, "city");
        FieldChecker.checkEmpty(county, "county");
        FieldChecker.checkEmpty(address, "address");
        FieldChecker.checkEmpty(consigneeName, "consigneeName");
        FieldChecker.checkEmpty(consigneePhone, "consigneePhone");
        if (!SimpleRegexUtils.isMobile(consigneePhone)) {
            throw new IllegalParamException("手机号格式不正确");
        }
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getCountyName() {
        return countyName;
    }

    public void setCountyName(String countyName) {
        this.countyName = countyName;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public Long getProvince() {
        return province;
    }

    public void setProvince(Long province) {
        this.province = province;
    }

    public Long getCity() {
        return city;
    }

    public void setCity(Long city) {
        this.city = city;
    }

    public Long getCounty() {
        return county;
    }

    public void setCounty(Long county) {
        this.county = county;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getConsigneeName() {
        return consigneeName;
    }

    public void setConsigneeName(String consigneeName) {
        this.consigneeName = consigneeName;
    }

    public String getConsigneePhone() {
        return consigneePhone;
    }

    public void setConsigneePhone(String consigneePhone) {
        this.consigneePhone = consigneePhone;
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable(Boolean available) {
        this.available = available;
    }

    public Boolean getDefaultAddress() {
        return defaultAddress;
    }

    public void setDefaultAddress(Boolean defaultAddress) {
        this.defaultAddress = defaultAddress;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
